package com.dianqiu.batch.dao.impl;

import java.util.List;

import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.springframework.stereotype.Component;

import com.dianqiu.base.dao.impl.BatchBaseDao;
import com.dianqiu.base.util.ListUtil;
import com.dianqiu.batch.bean.DqTempMatchesTO;
import com.dianqiu.batch.dao.DqTempMatchDao;
@Component("dqTempMatchDao")
public class DqTempMatchDaoImpl extends BatchBaseDao implements DqTempMatchDao {

	public void save(DqTempMatchesTO to) {
		getHibernateTemplate().save(to);
	}

	public void save(List<DqTempMatchesTO> tos) {
		int count = 1;
		Session session = getHibernateTemplate().getSessionFactory().openSession();
		Transaction txn = session.beginTransaction();
		if (ListUtil.isNotEmpty(tos)) {
			for (DqTempMatchesTO dqTempMatchesTO : tos) {
				dqTempMatchesTO.setId(count);
				count++;
				session.save(dqTempMatchesTO);
			}
		}
		txn.commit();
		session.close();
	}
	
	public void delete(){
		String sql = "from DqTempMatchesTO";
		Session session = getHibernateTemplate().getSessionFactory().openSession();	
		Transaction txn = session.beginTransaction();
		session.delete(sql);
		txn.commit();
		session.close();
	}

}
